﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.AdvTree;
using DevComponents.DotNetBar;

namespace project_assess.assess_relate
{
    public partial class manage_frm : Office2007Form
    {

        DataBase m_db;
        Mfrm mfrm;
        public manage_frm(Mfrm frm)
        {
            InitializeComponent();
            mfrm = frm;
            m_db = frm.m_db;
            load_all();
        }


        #region 方案编制
        //考核方案编制
        private void btn1_Click(object sender, EventArgs e)
        {
            message_frm frm;
            string sql;
            DataTable dt;
            if (mfrm.curprjid == null || mfrm.curprjid == "")
            {
                frm = new message_frm("没有选择工程", "错误", icon_img.alert1);
                frm.ShowDialog(this);
                frm.Close();
                return;
            }
            double a, b, c, d;
            try
            {
                a = Convert.ToDouble(comb1.Text);
                b = (comb2.Text == "是") ? 1 : 0.8;
                c = (comb3.Text == "是") ? 1 : 0.5;
                d = (comb4.Text == "是") ? 0.3 : 1;
            }
            catch
            {
                frm = new message_frm("参数填写不正确", "错误", icon_img.alert1);
                frm.ShowDialog(this);
                return;
            }
            sql = "select [工作量] from [projects] where [项目编号]='"
              + mfrm.curprjid + "'";
            dt = m_db.GetDataSet(sql).Tables[0];
            double max = Convert.ToDouble(dt.Rows[0][0]);
            double total;
            if (max > 100000)
            {
                max = 1000;
            }
            else if (max > 50000)
            {
                max = 500;
            }
            else
            {
                max = 200;
            }
            total=max;
            if (d == 0.3)
            {
                max = max * a * b * d;
            }
            else
            {
                max = max * a * b * c;
            }
            sql = "delete from [assess_manage] where [项目编号]='" + mfrm.curprjid + "' and [内容] like'%方案%'";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','方案编制额度'," + total + ","
                + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','方案质量'," + a + ","
            + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','方案外聘'," + b + ","
             + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','方案中标'," + c + ","
            + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','方案陪标'," + d + ","
            + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','方案核算'," + max + ","
            + "'','','','')";
            m_db.ExecuteSQL(sql);
            Node nn = new Node();
            nn.Text = "考核结果:";
            nn.Cells.Add(new Cell(max.ToString()));
            if (tree1.Nodes[0].Nodes.Count == 1)
            {
                tree1.Nodes[0].Nodes.Add(nn);
            }
            else
            {
                tree1.Nodes[0].Nodes.RemoveAt(1);
                tree1.Nodes[0].Nodes.Add(nn);
            }
        }
        //加载方案选项
        void load_fangan(double max)
        {
            double total;
            if (max > 100000)
            {
                total = 1000;
            }
            else if (max > 50000)
            {
                total = 500;
            }
            else
            {
                total = 200;
            }
            Node n = new Node();
            n.Text = mfrm.curprjid;
            Node nn = new Node();
            nn.Text = "考核额度:";
            nn.Cells.Add(new Cell(total.ToString()));
            n.Nodes.Add(nn);
            //l1.Text = "考核额度为:" + total;
            string sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
                + "' and [内容]='方案核算'";
            DataTable dt = m_db.GetDataSet(sql).Tables[0];
            double temp;
            if (dt != null && dt.Rows.Count == 1)
            {
                temp = Convert.ToDouble(dt.Rows[0][0]);
                //re1.Text = "考核结果为:" + temp;
                nn = new Node();
                nn.Text = "考核结果:";
                nn.Cells.Add(new Cell(temp.ToString()));
                n.Nodes.Add(nn);
                sql = "select [系数] from [assess_manage] where [项目编号]='"
                    + mfrm.curprjid + "' and [内容]='方案质量'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                comb1.Text = temp.ToString();
                sql = "select [系数] from [assess_manage] where [项目编号]='"
                   + mfrm.curprjid + "' and [内容]='方案外聘'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                comb2.Text = (temp == 0.8) ? "是" : "否";
                sql = "select [系数] from [assess_manage] where [项目编号]='"
          + mfrm.curprjid + "' and [内容]='方案中标'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                comb3.Text = (temp == 1) ? "是" : "否";
                sql = "select [系数] from [assess_manage] where [项目编号]='"
+ mfrm.curprjid + "' and [内容]='方案陪标'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                comb4.Text = (temp == 0.3) ? "是" : "否";
            }
            tree1.Nodes.Clear();
            n.Expanded = true;
            tree1.Nodes.Add(n);
        }
        #endregion
        #region 总结报告
        //总结报告考核
        private void btn2_Click(object sender, EventArgs e)
        {
            message_frm frm;
            string sql;
            DataTable dt;
            if (mfrm.curprjid == null || mfrm.curprjid == "")
            {
                frm = new message_frm("没有选择工程", "错误", icon_img.alert1);
                frm.ShowDialog(this);
                frm.Close();
                return;
            }
            double a;
            try
            {
                a = Convert.ToDouble(comb2_1.Text);
            }
            catch
            {
                frm = new message_frm("参数填写不正确", "错误", icon_img.alert1);
                frm.ShowDialog(this);
                return;
            }
            sql = "select [工作量] from [projects] where [项目编号]='"
              + mfrm.curprjid + "'";
            dt = m_db.GetDataSet(sql).Tables[0];
            double max = Convert.ToDouble(dt.Rows[0][0]);
            double total;
            if (max > 100000)
            {
                max = 2000;
            }
            else if (max > 50000)
            {
                max = 800;
            }
            else
            {
                max = 400;
            }
            total = max;
            max = max * a;
            sql = "delete from [assess_manage] where [项目编号]='" 
                + mfrm.curprjid + "' and [内容] like'%总结%'";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','总结报告额度'," + total + ","
              + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','总结质量'," + a + ","
            + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','总结核算'," + max + ","
   + "'','','','')";
            m_db.ExecuteSQL(sql);
            Node n = new Node();
            n.Text = "考核结果:";
            n.Cells.Add(new Cell(max.ToString()));
            if (tree2.Nodes[0].Nodes.Count == 1)
            {
                tree2.Nodes[0].Nodes.Add(n);
            }
            else
            {
                tree2.Nodes[0].Nodes.RemoveAt(1);
                tree2.Nodes[0].Nodes.Add(n);
            }
            
        }
        //加载总结报告考核内容
        void load_zongjie(double max)
        {
            double total;
            if (max > 100000)
            {
                total = 2000;
            }
            else if (max > 50000)
            {
                total = 800;
            }
            else
            {
                total = 400;
            }
            Node n = new Node();
            n.Text = mfrm.curprjid;
            Node nn = new Node();
            nn.Text = "考核额度:";
            nn.Cells.Add(new Cell(total.ToString()));
            n.Nodes.Add(nn);
            string sql; DataTable dt;
            sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
               + "' and [内容]='总结核算'";
            dt = m_db.GetDataSet(sql).Tables[0];
            double temp;
            if (dt != null && dt.Rows.Count == 1)
            {
                temp = Convert.ToDouble(dt.Rows[0][0]);
                nn = new Node();
                nn.Text = "考核结果:";
                nn.Cells.Add(new Cell(temp.ToString()));
                n.Nodes.Add(nn);
                sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
             + "' and [内容]='总结质量'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                comb2_1.Text = temp.ToString();
            }
            tree2.Nodes.Clear();
            n.Expanded = true;
            tree2.Nodes.Add(n);
        }
        #endregion



        #region 加载所有选项
        //加载所有已存入的选项
        void load_all()
        {
            if (mfrm.curprjid == null || mfrm.curprjid == "")
            {
                return;
            }
            string sql = "select [工作量] from [projects] where [项目编号]='"
          + mfrm.curprjid + "'";
            DataTable dt = m_db.GetDataSet(sql).Tables[0];
            double max = Convert.ToDouble(dt.Rows[0][0]);
            load_fangan(max);
            load_zongjie(max);
            load_prjquality(max);
            load_profilesubmit(max);
            load_other();
        }
        #endregion

        #region 工程质量
        //工程质量
        private void btn3_Click(object sender, EventArgs e)
        {
            message_frm frm;
            string sql;
            DataTable dt;
            if (mfrm.curprjid == null || mfrm.curprjid == "")
            {
                frm = new message_frm("没有选择工程", "错误", icon_img.alert1);
                frm.ShowDialog(this);
                frm.Close();
                return;
            }
            double a;
            try
            {
                a = Convert.ToDouble(comb3_1.Text);
            }
            catch
            {
                frm = new message_frm("参数填写不正确", "错误", icon_img.alert1);
                frm.ShowDialog(this);
                return;
            }
            sql = "select [工作量] from [projects] where [项目编号]='"
              + mfrm.curprjid + "'";
            dt = m_db.GetDataSet(sql).Tables[0];
            double max = Convert.ToDouble(dt.Rows[0][0]);
            double total;
            if (max > 100000)
            {
                max = 3000;
            }
            else if (max > 50000)
            {
                max = 2000;
            }
            else
            {
                max = 1000;
            }
            total = max;
            max = max * (a - 1);
            sql = "delete from [assess_manage] where [项目编号]='"
                + mfrm.curprjid + "' and [内容] like'%工程质量%'";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','工程质量额度'," + total + ","
              + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','工程质量'," + a + ","
            + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','工程质量核算'," + max + ","
   + "'','','','')";
            m_db.ExecuteSQL(sql);
            Node n = new Node();
            n.Text = "考核结果:";
            n.Cells.Add(new Cell(max.ToString()));
            if (tree3.Nodes[0].Nodes.Count == 1)
            {
                tree3.Nodes[0].Nodes.Add(n);
            }
            else
            {
                tree3.Nodes[0].Nodes.RemoveAt(1);
                tree3.Nodes[0].Nodes.Add(n);
            }
        }
        //加载工程质量
        void load_prjquality(double max)
        {
            double total;
            if (max > 100000)
            {
                total = 3000;
            }
            else if (max > 50000)
            {
                total = 2000;
            }
            else
            {
                total = 1000;
            }
            Node n = new Node();
            n.Text = mfrm.curprjid;
            Node nn = new Node();
            nn.Text = "考核额度:";
            nn.Cells.Add(new Cell(total.ToString()));
            n.Nodes.Add(nn);
            string sql; DataTable dt;
            sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
               + "' and [内容]='工程质量核算'";
            dt = m_db.GetDataSet(sql).Tables[0];
            double temp;
            if (dt != null && dt.Rows.Count == 1)
            {
                temp = Convert.ToDouble(dt.Rows[0][0]);
                nn = new Node();
                nn.Text = "考核结果:";
                nn.Cells.Add(new Cell(temp.ToString()));
                n.Nodes.Add(nn);

                sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
             + "' and [内容]='工程质量'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                comb3_1.Text = temp.ToString();
            }
            tree3.Nodes.Clear();
            n.Expanded = true;
            tree3.Nodes.Add(n);
        }
        #endregion

       


        #region 资料归档
        private void buttonX1_Click(object sender, EventArgs e)
        {
            message_frm frm;
            string sql;
            DataTable dt;
            if (mfrm.curprjid == null || mfrm.curprjid == "")
            {
                frm = new message_frm("没有选择工程", "错误", icon_img.alert1);
                frm.ShowDialog(this);
                frm.Close();
                return;
            }
            double a;
            try
            {
                a = Convert.ToDouble(comb4_1.Text);
            }
            catch
            {
                frm = new message_frm("参数填写不正确", "错误", icon_img.alert1);
                frm.ShowDialog(this);
                return;
            }
            sql = "select [工作量] from [projects] where [项目编号]='"
              + mfrm.curprjid + "'";
            dt = m_db.GetDataSet(sql).Tables[0];
            double max = Convert.ToDouble(dt.Rows[0][0]);
            double total;
            if (max > 100000)
            {
                max = 500;
            }
            else if (max > 50000)
            {
                max = 300;
            }
            else
            {
                max = 200;
            }
            total = max;
            max = max * (a);
            sql = "delete from [assess_manage] where [项目编号]='"
                + mfrm.curprjid + "' and [内容] like'%资料归档%'";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','资料归档额度'," + total + ","
              + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','资料归档'," + a + ","
            + "'','','','')";
            m_db.ExecuteSQL(sql);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','资料归档核算'," + max + ","
   + "'','','','')";
            m_db.ExecuteSQL(sql);
            Node n = new Node();
            n.Text = "考核结果:";
            n.Cells.Add(new Cell(max.ToString()));
            if (tree4.Nodes[0].Nodes.Count == 1)
            {
                tree4.Nodes[0].Nodes.Add(n);
            }
            else
            {
                tree4.Nodes[0].Nodes.RemoveAt(1);
                tree4.Nodes[0].Nodes.Add(n);
            }
        }
        void load_profilesubmit(double max)
        {
            double total;
            if (max > 100000)
            {
                total = 500;
            }
            else if (max > 50000)
            {
                total = 300;
            }
            else
            {
                total = 200;
            }
            Node n = new Node();
            n.Text = mfrm.curprjid;
            Node nn = new Node();
            nn.Text = "考核额度:";
            nn.Cells.Add(new Cell(total.ToString()));
            n.Nodes.Add(nn);
            string sql; DataTable dt;
            sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
               + "' and [内容]='资料归档核算'";
            dt = m_db.GetDataSet(sql).Tables[0];
            double temp;
            if (dt != null && dt.Rows.Count == 1)
            {
                temp = Convert.ToDouble(dt.Rows[0][0]);
                nn = new Node();
                nn.Text = "考核结果:";
                nn.Cells.Add(new Cell(temp.ToString()));
                n.Nodes.Add(nn);

                sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
             + "' and [内容]='资料归档'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                comb4_1.Text = temp.ToString();
            }
            tree4.Nodes.Clear();
            n.Expanded = true;
            tree4.Nodes.Add(n);
        }
        #endregion


        #region 其他考核内容
        private void buttonX2_Click(object sender, EventArgs e)
        {
            double a, b, c, d, x, y; message_frm frm;
            if (mfrm.curprjid == null || mfrm.curprjid == "")
            {
                frm = new message_frm("没有选择工程", "错误", icon_img.alert1);
                frm.ShowDialog(this);
                frm.Close();
                return;
            }
            try
            {
                a = integerInput1.Value; b = integerInput2.Value; c = integerInput3.Value; d = integerInput4.Value;
                x = integerInput5.Value; y = integerInput6.Value;
            }
            catch
            {
                frm = new message_frm("参数错误", "错误", icon_img.alert1);
                frm.ShowDialog(this);
                frm.Close();
                return;
            }
            string sql = "delete from [assess_manage] where [项目编号]='" + mfrm.curprjid + "' and [内容] like'%其他%'";
            m_db.ExecuteSQL(sql);


            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','其他书面表扬'," + a * 200 + ","
          + "'','','','')";
            m_db.ExecuteSQL(sql);


            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','其他中间报告'," + b * -200 + ","
          + "'','','','')";
            m_db.ExecuteSQL(sql);

            double z = (comboBoxEx2.Text == "有") ? 0 : -200;
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','其他项目内容'," + z + ","
+ "'','','','')";
            m_db.ExecuteSQL(sql);

            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','其他环境安全'," + c * -200 + ","
+ "'','','','')";
            m_db.ExecuteSQL(sql);

            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','其他所内检查'," + d * -100 + ","
+ "'','','','')";
            m_db.ExecuteSQL(sql);

            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','其他公司检查'," + x * -300 + ","
+ "'','','','')";
            m_db.ExecuteSQL(sql);

            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','其他外部检查'," + y * -600 + ","
+ "'','','','')";
            m_db.ExecuteSQL(sql);

            double max = a * 200 + b * -200 + z + c * -200 + d * -100 + x * -300 + y * -600;
            Node n = new Node();
            n.Text = "考核结果:";
            n.Cells.Add(new Cell(max.ToString()));
            tree5.Nodes[0].Nodes.Clear();
            tree5.Nodes[0].Nodes.Add(n);
            sql = "insert into [assess_manage] values('" + mfrm.curprjid + "','其他'," + max + "," + "'','','','')";
            m_db.ExecuteSQL(sql);

        }

        void load_other()
        {
              string sql; DataTable dt;
            sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
               + "' and [内容]='其他'";
            dt = m_db.GetDataSet(sql).Tables[0];
            double temp;
            Node n = new Node();
            n.Text = mfrm.curprjid;
            if (dt != null && dt.Rows.Count == 1)
            {
                temp = Convert.ToDouble(dt.Rows[0][0]);
                Node nn = new Node();
                nn.Text = "考核结果:";
                nn.Cells.Add(new Cell(temp.ToString()));
                n.Nodes.Add(nn);

                sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
              + "' and [内容]='其他书面表扬'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                integerInput1.Value = (int)temp / 200;

                sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
             + "' and [内容]='其他中间报告'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                integerInput2.Value = (int)temp / -200;

                sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
           + "' and [内容]='其他项目内容'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                comboBoxEx2.Text = temp == 0 ? "有" : "无";

                sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
           + "' and [内容]='其他环境安全'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                integerInput3.Value = (int)temp / -200;

                sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
     + "' and [内容]='其他所内检查'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                integerInput4.Value = (int)temp / -100;

                sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
+ "' and [内容]='其他公司检查'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                integerInput5.Value = (int)temp / -300;

                sql = "select [系数] from [assess_manage] where [项目编号]='" + mfrm.curprjid
+ "' and [内容]='其他外部检查'";
                dt = m_db.GetDataSet(sql).Tables[0];
                temp = Convert.ToDouble(dt.Rows[0][0]);
                integerInput6.Value = (int)temp / -600;
            }
            tree5.Nodes.Clear();
            n.Expanded = true;
            tree5.Nodes.Add(n);
        }
        #endregion


        private void comb3_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comb3.SelectedIndex == 0)
            {
                comb4.SelectedIndex = 1;
            }
        }
    }
}
